package com.aaa.ql1229.controller;


import com.aaa.ql1229.entity.Userinfo;
import com.aaa.ql1229.entity.vo.PageParam;
import com.aaa.ql1229.entity.vo.ResponseMode;
import com.aaa.ql1229.service.IUserinfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ql
 * @since 2022-12-29
 */
@RestController
@RequestMapping("/userinfo")
public class UserinfoController {

    @Autowired
    private IUserinfoService userinfoService;

    @DeleteMapping("{id}")
    public ResponseMode del(@PathVariable Integer id){
        ResponseMode<Userinfo> userinfoResponseMode = new ResponseMode<>();
        boolean b = userinfoService.removeById(id);
        if (b){
            userinfoResponseMode.setCode(0).setMsg("删除失败");
        }
        return userinfoResponseMode;
    }

    @PostMapping("addOrUpd")
    public ResponseMode istOrUpd(Userinfo userinfo){
        ResponseMode<Userinfo> userinfoResponseMode = new ResponseMode<>();
        boolean b = userinfoService.saveOrUpdate(userinfo);
        if (b){
            userinfoResponseMode.setCode(0).setMsg("添加/修改成功");
        }else {
            userinfoResponseMode.setCode(1).setMsg("添加/修改失败");
        }
        return userinfoResponseMode;
    }

    @GetMapping("sellike")
    public ResponseMode sel(Userinfo userinfo, PageParam pageParam){
        IPage<Userinfo> page=userinfoService.selOrPage(userinfo,pageParam);
        return new ResponseMode<Page<Userinfo>>().setExtra(page);
    }

}

